<?php

/**
 * SelfController.class.php 
 * 
 *
 * @author     late.xiao@qq.com
 */
namespace Sysmanger\Controller;

use System\Common\SystemController;

class SelfController extends SystemController {

    public function index()
    {
        $this->system_title = '账号信息';
        $manger_info = session('manger');
        $obj_serv = D('Manger', 'Service');
        $obj_serv->formatMangerInfo($manger_info);
        $this->assign('manger', $manger_info);
        return $this->loadSystemView();
    }
    
    

    public function updatepwd()
    {
        $act_url = U('Self/savepwd');
        $this->assign('act_url', $act_url);
        $this->loadSystemView();
    }
    
    public function savepwd()
    {
        $request = I('post.');
        $mid = session('manger.mid');
        $obj_serv = D('Passport', 'Service');
        try {
            $pwd_info = array();
            $obj_serv->savePwd($request, $mid, $pwd_info);
            $this->_setSession($pwd_info);
        } catch (\Exception $e) {
            $msg = $e->getMessage();
            
            return $this->error($msg);
        }
        
        return $this->success('保存成功',U('Self/index'));
        
    }
    
    public function _setSession($pwd_info)
    {
        session('manger.passwd', $pwd_info['passwd']);
        session('manger.salt', $pwd_info['salt']);
        
        return true;
    }
} 